package view.employee;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dal.employee.Employee;
import dal.employee.EmployeeUtil;

/**
 * Servlet implementation class DeleteEmployee
 */
@WebServlet("/DeleteEmployee")
public class DeleteEmployee extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public DeleteEmployee() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter printWriter=response.getWriter();
		response.setContentType("text/HTML");
		try {

			String deleteText = request.getParameter("deleteText");
			System.out.println(deleteText);
			
			//Employee employee = new Employee();
			EmployeeUtil employeeUtil = new EmployeeUtil();

			//employee.setEmployeeId(employee.getEmployeeId());

			Boolean isOk=employeeUtil.delete(deleteText);
			
			System.out.println(isOk);
			
			if(isOk==true)
			{
			printWriter.print(""
					+ "<b>"
					+ " Employee Information Deleted Succesfully "
					+ "</b>");
			}
			else{
				printWriter.print(""
						+ "<b>"
						+ " Selected Employee Id is Not present,Please try Again "
						+ "</b>");
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			printWriter.print(""
					+ "<b>"
					+ " Error "
					+ "</b>");
			
			System.out.println("Exception from delete post");
		}
	}

}
